#! /bin/sh
# PCP QA Test No. 251
# libpcp for archives with missing volumes
#
# Copyright (c) 1995-2002 Silicon Graphics, Inc.  All Rights Reserved.
#

seq=`basename $0`
echo "QA output created by $seq"

# get standard filters
. ./common.product
. ./common.filter
. ./common.check

_filter()
{
    sed \
	-e '/host:/s/ [^ ].*/ HOST/' \
	-e '/start:/s/ [^ ].*/ DATE/' \
	-e '/end:/s/ [^ ].*/ DATE/' \
	-e 's/^..:..:..\..../TIMESTAMP   /' \
	-e '/No values available/d'
    if [ "`echo core*`" != "core*" ]
    then
	$PCP_ECHO_PROG $PCP_ECHO_N "Dumped core! ... saved in""$PCP_ECHO_C"
	$sudo rm -f $here/core*
	for c in core*
	do
	    $sudo mv $c $here/$c
	    $PCP_ECHO_PROG $PCP_ECHO_N " $here/$c""$PCP_ECHO_C"
	done
	echo
	touch die
    fi
}

status=1	# failure is the default!
trap "cd $here; rm -rf $tmp $tmp.*; exit \$status" 0 1 2 3 15

# real QA test starts here
mkdir $tmp
cp archives/ok-mv-bar.* $tmp
offset=`_arch_start archives/ok-mv-bar 0`
echo "offset=$offset" >>$seq_full
pmdumplog -dilmst -z archives/ok-mv-bar >>$seq_full
cd $tmp

for inst in "bin-100" "bin-100,bin-500,bin-900"
do
    echo
    echo "All volumes present ... $inst ..." | tee -a $seq_full
    pmval -z -O $offset -Dlog -t2 -a ok-mv-bar -i $inst sampledso.bin 2>$tmp.err >$tmp.out
    cat $tmp.err >>$seq_full
    grep '^__pmLogChangeVol:' $tmp.err
    _filter <$tmp.out
    [ -f die ] && exit

    echo
    echo "First volume missing ... $inst ..." | tee -a $seq_full
    mv ok-mv-bar.0 foo.0
    pmval -z -O $offset -Dlog -t2 -a ok-mv-bar -i $inst sampledso.bin 2>$tmp.err >$tmp.out
    cat $tmp.err >>$seq_full
    grep '^__pmLogChangeVol:' $tmp.err
    _filter <$tmp.out
    [ -f die ] && exit
    mv foo.0 ok-mv-bar.0

    echo
    echo "Last volume missing ... $inst ..." | tee -a $seq_full
    mv ok-mv-bar.3 foo.3
    pmval -z -O $offset -Dlog -t2 -a ok-mv-bar -i $inst sampledso.bin 2>$tmp.err >$tmp.out
    cat $tmp.err >>$seq_full
    grep '^__pmLogChangeVol:' $tmp.err
    _filter <$tmp.out
    [ -f die ] && exit
    mv foo.3 ok-mv-bar.3

    echo
    echo "Second volume missing ... $inst ..." | tee -a $seq_full
    mv ok-mv-bar.1 foo.1
    pmval -z -O $offset -Dlog -t2 -a ok-mv-bar -i $inst sampledso.bin 2>$tmp.err >$tmp.out
    cat $tmp.err >>$seq_full
    grep '^__pmLogChangeVol:' $tmp.err
    _filter <$tmp.out
    [ -f die ] && exit
    mv foo.1 ok-mv-bar.1

    echo
    echo "Second last volume missing ... $inst ..." | tee -a $seq_full
    mv ok-mv-bar.2 foo.2
    pmval -z -O $offset -Dlog -t2 -a ok-mv-bar -i $inst sampledso.bin 2>$tmp.err >$tmp.out
    cat $tmp.err >>$seq_full
    grep '^__pmLogChangeVol:' $tmp.err
    _filter <$tmp.out
    [ -f die ] && exit
    mv foo.2 ok-mv-bar.2

    echo
    echo "All volumes but second missing ... $inst ..." | tee -a $seq_full
    mv ok-mv-bar.0 foo.0
    mv ok-mv-bar.2 foo.2
    mv ok-mv-bar.3 foo.3
    pmval -z -O $offset -Dlog -t2 -a ok-mv-bar -i $inst sampledso.bin 2>$tmp.err >$tmp.out
    cat $tmp.err >>$seq_full
    grep '^__pmLogChangeVol:' $tmp.err
    _filter <$tmp.out
    [ -f die ] && exit
    mv foo.0 ok-mv-bar.0
    mv foo.2 ok-mv-bar.2
    mv foo.3 ok-mv-bar.3

done

# success, all done
status=0
exit
